<template>
  <basic-container>
    <div class="c_card">
      <div class="c_card_item" v-if="userType==1">
        <div class="c_card_label">我的资产</div>
        <el-card class="box-card">
          <div class="b_money" style="margin-top:52px;">{{paymoeny}}元</div>
          <div class="c_btn2">
            <el-button class="btn" @click="()=>{this.accountShow=true}">查看详情</el-button>
            <el-button class="btn">去确认</el-button>
          </div>
        </el-card>
      </div>
      <div class="c_card_item" v-if="userType==0">
        <div class="c_card_label">我的资产</div>
        <el-card class="box-card">
          <div class="b_money">元</div>
          <div class="box_box">
              <div class="box_money">{{paymoeny}}元</div>
              <div class="box_txt">待确认</div>
            </div>
          <div class="c_btn2">
            <el-button class="btn" @click="()=>{this.accountShow=true}">查看详情</el-button>
            <el-button class="btn">去确认</el-button>
          </div>
        </el-card>
      </div>
      <div class="c_card_item">
        <div class="c_card_label">钱包余额</div>
        <el-card class="box-card">
          <div class="b_money">{{paymoeny}}元</div>
          <div class="b_typeBox">
            <div class="bt_box">
              <div class="bt_money">{{paymoeny}}元</div>
              <div class="bt_txt">可提</div>
            </div>
            <div class="bt_line"></div>
            <div class="bt_box">
              <div class="bt_money">{{paymoeny}}元</div>
              <div class="bt_txt">欠款</div>
            </div>
          </div>
          <div class="c_btn1">
            <el-button class="btn" @click="()=>{this.takeOutShow=true}">去提现</el-button>
          </div>
        </el-card>
      </div>
      <div class="c_card_item" v-if="userType==1">
        <div class="c_card_label">发票管理</div>
        <el-card class="box-card">
          <div class="b_money">{{paymoeny}}元</div>
          <div class="b_typeBox">
            <div class="bt_box">
              <div class="bt_money">{{paymoeny}}元</div>
              <div class="bt_txt">待开</div>
            </div>
            <div class="bt_line"></div>
            <div class="bt_box">
              <div class="bt_money">{{paymoeny}}元</div>
              <div class="bt_txt">待审</div>
            </div>
          </div>
          <div class="c_btn1">
            <el-button class="btn" @click="goToInvoice">去开票</el-button>
          </div>
        </el-card>
      </div>
      <div class="c_card_item" v-if="userType==0">
        <div class="c_card_label">累计提现</div>
        <el-card class="box-card">
          <div class="b_money" style="margin-top:52px;">{{paymoeny}}元</div>
        </el-card>
      </div>
    </div>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
      @on-load="onLoad"
    >
    <!-- 
      @row-update="rowUpdate"               编辑数据后确定触发该事件
      @row-save="rowSave"                   新增数据后点击确定触发该事件
      @row-del="rowDel"                     行数据删除时触发该事件
      @search-change="searchChange"         击搜索后触发该事件(由于page分页信息和search搜索信息是sync修饰符，可以直接通过this.page和this.search拿到)
      @search-reset="searchReset"           清空搜索回调方法
      @selection-change="selectionChange"   当选择项发生变化时会触发该事件
      @current-change="currentChange"       分页页码改变时会触发
      @size-change="sizeChange"             pageSize改变时会触发 
      @refresh-change="refreshChange"       点击刷新按钮触发该事件(由于page分页信息和search搜索信息是sync修饰符，可以直接通过this.page和this.search拿到)
      @sort-change="sortChange"             当表格的排序条件发生变化的时候会触发该事件
      @on-load="onLoad"                   
     -->
    </avue-crud>

    <el-dialog
      title="我的资产"
      append-to-body
      :visible.sync="accountShow"
      :close-on-click-modal="false"
      width="444px"
    >
      <div class="datail">日结：0 元</div>
      <div class="datail">月结：0 元</div>
      <div class="datail">欠款：0 元</div>
      <!-- <div class="datail">奖励：0 元</div> -->
      <div class="datail">可提现：0 元</div>
    </el-dialog>
    <el-dialog
      title="提现"
      append-to-body
      :visible.sync="takeOutShow"
      :close-on-click-modal="false"
      ref="takeOut_dialog"
      v-if="takeOutShow"
      width="444px"
      :before-close="beforeClose_takeOut"
    >
        <div class="box_form" v-loading="takeOutLoading"  element-loading-text="加载中...">
          <el-form ref="takeOutFrom" :rules="rules" :label-position="'top'" status-icon label-width="80px" :model="takeOutFrom">
            <el-form-item label="提现金额" prop='paymoeny'>
              <!-- <el-input v-model="takeOutFrom.paymoeny" type="number" clearable></el-input> -->
              <el-input-number class="inputNumber" size="small" v-model="takeOutFrom.paymoeny" :min="0" :precision="2" />
            </el-form-item>
            <div class="takeOutAll" @click="takeOutAll">全部提现</div>

            <!-- <el-form-item label="账户名">
              <el-input v-model="takeOutFrom.region"></el-input>
            </el-form-item>
            <el-form-item label="账户号">
              <el-input v-model="takeOutFrom.region"></el-input>
            </el-form-item>
            <el-form-item label="开户行">
              <el-input v-model="takeOutFrom.type"></el-input>
            </el-form-item> -->
          </el-form>

          <div class="form_money">账户名：xxx</div>
          <div class="form_money">账户号：xxx</div>
          <div class="form_money">开户行：xxx</div>
          <div class="form_money">服务费：0元</div>
          <div class="form_money">手续费：0元</div>
          <div class="form_money">实际入账：0元</div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitTakeOutFrom">提现</el-button>
        </span>
    </el-dialog>
  </basic-container>
</template>

<script>
import {
  getList
} from "@/api/rb-service/store/store";
import { mapGetters } from "vuex";
// import { getToken } from "@/util/auth";
export default {
  data() {
    var validatePaymoeny = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入提现金额（不少于100元）'));
      } else if (value < 100) {
        callback(new Error('请输入提现金额（不少于100元）'));
      } else {
        callback();
      }
    };
    return {
      paymoeny:0,
      form: {},
      query: {},
      search: {},
      loading: true,
      takeOutLoading:false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "auto",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        addBtn:false,
        viewBtn: true,
        selection: true,
        searchMenuSpan: 6,
        columnBtn: false,
        editBtn:false,// 编辑按钮
        delBtn:false,// 删除
        // menuWidth:150,       //操作栏宽度
        // labelWidth:120,      //弹出表单的标题的统一宽度
        // searchLabelWidth: 150, //搜索框标题宽度
        column: [
          {
            label: "开户名称",
            prop: "rsSn",
            type: "input",
            sortable: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入开户名称",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
          {
            label: "开户行",
            prop: "rsParam",
            type: "input",
            search: true,
            rules: [
              {
                required: true,
                message: "请输入开户行",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
          {
            label: "账户类型",
            prop: "rsSn",
            type: "input",
            sortable: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入账户类型",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
          {
            label: "转账类型",
            prop: "rsParam",
            type: "input",
            search: true,
            rules: [
              {
                required: true,
                message: "请输入转账类型",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
          {
            label: "提现日期",
            prop: "rsSn",
            type: "datetime",
            format:'yyyy-MM-dd hh:mm:ss',
            valueFormat:'yyyy-MM-dd hh:mm:ss',
            sortable: true,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入体现日期",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
          {
            label: "审核日期",
            prop: "rsParam",
            type: "datetime",
            format:'yyyy-MM-dd hh:mm:ss',
            valueFormat:'yyyy-MM-dd hh:mm:ss',
            search: true,
            rules: [
              {
                required: true,
                message: "请输入开户行",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
          {
            label: "审核日期",
            prop: "rsParam",
            type: "datetime",
            format:'yyyy-MM-dd hh:mm:ss',
            valueFormat:'yyyy-MM-dd hh:mm:ss',
            search: true,
            rules: [
              {
                required: true,
                message: "请输入开户行",
                trigger: "blur",
              },
            ],
            overHidden:true,
          },
        ],
      },
      data: [],
      accountShow:false,
      takeOutShow:false,
      takeOutFrom:{},
      rules: {
        paymoeny: [
          // { validator: validatePaymoeny, trigger: ['blur', 'change'] }
          { validator: validatePaymoeny, trigger: ['blur'] }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(["permission","userType"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.store_add, false),
        viewBtn: this.vaildData(this.permission.store_view, false),
        delBtn: this.vaildData(this.permission.store_delete, false),
        editBtn: this.vaildData(this.permission.store_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  created(){
    this.paymoeny=512487451.521520;
  },
  methods: {
    goToInvoice(){
      this.$router.push({ path: '/rb-service/invoice/invoice' })
    },
    // 全部提现
    takeOutAll(){
      this.takeOutFrom.paymoeny=100.01
    },
    // 提现关闭回调
    beforeClose_takeOut(done){
      this.takeOutFrom={};
      done();
    },
    // 提现表单--提交
    submitTakeOutFrom() {
      this.$refs['takeOutFrom'].validate((valid) => {
        if (valid) {
          this.takeOutLoading=true;
          setTimeout(() => {
            this.$message({
              type: "success",
              message: "操作成功!",
            });
            this.takeOutShow=false;
            this.takeOutLoading=false;
            this.takeOutFrom={};
          }, 2000);
        } else {
          return false;
        }
      });
    },
    // handleDelete() {},
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then((res) => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    // 清空搜索回调方法
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    // 击搜索后触发该事件(由于page分页信息和search搜索信息是sync修饰符，可以直接通过this.page和this.search拿到)
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    // 当选择项发生变化时会触发该事件
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    // 分页页码改变时会触发
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    // pageSize改变时会触发 
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    // 点击刷新按钮触发该事件(由于page分页信息和search搜索信息是sync修饰符，可以直接通过this.page和this.search拿到)
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      // this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
        this.$forceUpdate()
      });
    },
    // 当表格的排序条件发生变化的时候会触发该事件
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    },
  },
};
</script>

<style lang="scss" scoped>
.c_card{
  display: flex;
  margin-bottom: 32px;
  .c_card_item{
    margin-right: 16px;
    .c_card_label{
      height: 24px;
      font-size: 16px;
      font-family: Source Han Sans CN-Medium, Source Han Sans CN;
      font-weight: 500;
      line-height: 24px;
      color: #000;
      margin-bottom: 8px;
    }
    .box-card /deep/ .el-card__body{
      width: 288px;
      height: 216px;
      padding: 16px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      cursor: pointer;
      .b_money{
        margin-top: 16px;
        font-weight: 500;
        color: #000000;
        line-height: 36px;
        font-size: 26px;
        text-align: center;
        
        overflow: hidden;
      }
      .box_box{
        .box_money{
          height: 20px;
          font-size: 14px;
          font-family: Source Han Sans CN-Regular, Source Han Sans CN;
          color: #000000;
          line-height: 20px;
          text-align: center;
        }
        .box_txt{
          height: 20px;
          font-size: 14px;
          font-family: Source Han Sans CN-Regular, Source Han Sans CN;
          color: #000000;
          line-height: 20px;
          margin-top: 10px;
          text-align: center;

          overflow: hidden;
        }
      }
      .b_typeBox{
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .bt_line{
          width: 1px;
          height: 28px;
          border-left: #000 solid 1px;
        }
        .bt_box{
          width: 128px;
          .bt_money{
            height: 20px;
            font-size: 14px;
            font-family: Source Han Sans CN-Regular, Source Han Sans CN;
            color: #000000;
            line-height: 20px;
            text-align: center;
          }
          .bt_txt{
            height: 20px;
            font-size: 14px;
            font-family: Source Han Sans CN-Regular, Source Han Sans CN;
            color: #000000;
            line-height: 20px;
            text-align: center;
            margin-top: 10px;

            overflow: hidden;
          }

          
        }

      }
      .c_btn2{
        width: 100%;
        display: flex;
        justify-content: space-between;
        .btn{
          width: 120px;
        }
      }
      .c_btn1 .btn{
          width: 256px;
      }
    }
  }
}

.datail{
  padding-left: 141px;
  height: 20px;
  font-size: 14px;
  font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  color: #000000;
  line-height: 20px;
  margin-bottom: 16px;
}

.box_form{
  width: 280px;
  margin: auto;
}
.form_money{
  width: 112px;
  height: 20px;
  font-size: 14px;
  font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  color: #000000;
  line-height: 20px;
  margin-bottom: 16px;
}
/deep/ .el-form-item__label{
  color: #000;
  font-weight: 500;
}
.el-form--label-top /deep/ .el-form-item__label{
  padding: 0;
}
.takeOutAll{
  height: 20px;
  font-size: 14px;
  font-weight: 500;
  color: #000;
  cursor: pointer;
  text-align: right;
  margin-top: -18px;
}
/deep/ .el-input-number__decrease,/deep/ .el-input-number__increase{
  display: none;
}
.inputNumber /deep/ .el-input__inner{
  padding-left: 15px;
  padding-right: 15px;
  width: 280px;
  text-align: left;
}
</style>
